<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :md="5" :sm="12">
            <a-form-item label="路口编号">
              <!-- <j-input placeholder="路口编号" v-model="queryParam.code"></j-input> -->
              <a-input placeholder="路口编号" v-model="queryParam.code"></a-input>
            </a-form-item>
          </a-col>
          <a-col :md="5" :sm="8">
            <a-form-item label="路口名称">
              <!-- <j-input placeholder="路口名称" v-model="queryParam.name"></j-input>  -->
              <a-input placeholder="路口名称" v-model="queryParam.name"></a-input>
            </a-form-item>
          </a-col>
          <a-col :md="5" :sm="8">
            <a-form-item label="路口标签">
                <j-multi-select-tag
                  v-model="queryParam.crossTag"
                  dictCode="road_tag"
                  placeholder="请选择">
                </j-multi-select-tag>
            </a-form-item>
          </a-col>
          <a-col :md="5" :sm="8">
            <a-form-item label="路口等级">
              <j-dict-select-tag v-model="queryParam.level" dictCode="cross_level" placeholder="路口等级"/>
            </a-form-item>
          </a-col>

          <a-col :md="4" :sm="8">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>

        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-row :gutter="24">
        <a-col :md="18" :sm="8">
          <a-button @click="viewInList" type="primary" :class="{active: viewMode === 'list'}" icon="ordered-list">列表模式</a-button>
          <a-button @click="viewInMap" type="primary" :class="{active: viewMode === 'map'}" icon="global">地图模式</a-button>
        </a-col>

        <a-col :md="6" :sm="8">
          <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
          <a-button type="primary" icon="download" @click="handleExportXls('路口表')">导出</a-button>
          <!-- <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
            <a-button type="primary" icon="import">导入</a-button>
          </a-upload> -->
          <a-button type="primary" icon="delete" @click="batchDel">删除</a-button>
        </a-col>
      </a-row>
    </div>

    <!-- table区域-begin -->
    <div v-show="viewMode === 'list'">
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text,record">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" :preview="record.id" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="viewRoadDetail(record)">详情</a>
          <a-divider type="vertical" />
          <a @click="handleEdit(record)">修改</a>
        </span>

      </a-table>
    </div>
    <!-- 地图视图 -->
    <div v-if="viewMode === 'map'" class="map-container">
       <t-cross-map-view 
        :queryParams="queryParam"
      />
    </div>

    <t-crossing-modal ref="modalForm" @ok="modalFormOk"></t-crossing-modal>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import TCrossingModal from './modules/TCrossingModal'
  import TCrossMapView from './modules/TCrossMapView'  

  export default {
    name: 'TCrossingList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      TCrossingModal,
      TCrossMapView      
    },
    data () {
      return {
        description: 't_crossing管理页面',
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'路口编号',
            align:"center",
            dataIndex: 'code'
          },
          {
            title:'路口名称',
            align:"center",
            dataIndex: 'name'
          },

          // {
          //   title:'wgs84路口经度',
          //   align:"center",
          //   dataIndex: 'lng'
          // },
          // {
          //   title:'wgs84路口纬度',
          //   align:"center",
          //   dataIndex: 'lat'
          // },
          {
            title:'路口标签',
            align:"center",
            dataIndex: 'crossTag_dictText'
          },
          // {
          //   title:'行政区域',
          //   align:"center",
          //   dataIndex: 'adminAreaName'
          // },
          {
            title:'示范区',
            align:"center",
            dataIndex: 'zoneId_dictText'
          },
          {
            title:'路口等级',
            align:"center",
            dataIndex: 'level_dictText'
          },

          // {
          //   title:'道路id',
          //   align:"center",
          //   dataIndex: 'roadId'
          // },
          {
            title:'所属道路',
            align:"center",
            dataIndex: 'roadName'
          },
          {
            title:'路口形态',
            align:"center",
            dataIndex: 'crossForm_dictText'
          },
          {
            title:'关联杆件数',
            align:"center",
            dataIndex: 'poleNum'
          },
          {
            title:'设备数量',
            align:"center",
            dataIndex: 'deviceNum'
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/basicinfo/roadSurface/crossing/list",
          delete: "/basicinfo/roadSurface/crossing/delete",
          deleteBatch: "/basicinfo/roadSurface/crossing/deleteBatch",
          exportXlsUrl: "/basicinfo/roadSurface/crossing/exportXls",
          importExcelUrl: "basicinfo/roadSurface/crossing/importExcel",
          
        },
        dictOptions:{},
        superFieldList:[],
        viewMode:'list'    
      }
    },
    created() {
      this.getSuperFieldList();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      initDictConfig(){
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'string',value:'roadId',text:'道路id'})
        fieldList.push({type:'string',value:'code',text:'路口编号'})
        fieldList.push({type:'string',value:'name',text:'路口名称'})
        fieldList.push({type:'string',value:'lng',text:'wgs84路口经度'})
        fieldList.push({type:'string',value:'lat',text:'wgs84路口纬度'})
        fieldList.push({type:'string',value:'level',text:'路口等级'})
        fieldList.push({type:'int',value:'ifBuild',text:'是否建设（0表示否，1表示是）'})
        fieldList.push({type:'int',value:'delFlag',text:'删除状态（0表示否，1表示是）'})
        this.superFieldList = fieldList
      },
      viewInList(){
        this.viewMode = 'list';
      },
      viewInMap(){
        this.viewMode = 'map';
        // this.$refs.mapView.init();
      },
      viewRoadDetail(record){
        this.$refs.modalForm.view(record);
        this.$refs.modalForm.title="详情";
        this.$refs.modalForm.disableSubmit = true;
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
  .ant-btn .active {
    background-color: #1890ff;
    border-color: #1890ff;
    color: #fff;
  }
  .map-container{
    width: 100%;
    height:600px;
  }
</style>